package com.nondo.dean.platform.controller.api.inner;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.web.View;
import com.nondo.dean.platform.domain.Grade;
import com.nondo.dean.platform.service.GradeService;

/**
 * 等级管理内部接口
 * @author zlj
 * @date 2018年3月27日
 */
@RestController("apiInnerGrade")
@RequestMapping("/{v}/inner/grade")
public class GradeController {
    
    @Autowired
    GradeService gradeService;
    
    /**
     * 查看等级详情
     * @param request
     * @param response
     * @param id
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/info/{id}")
    public View<Grade> info(HttpServletRequest request, HttpServletResponse response,
            @PathVariable("id") Integer id) {
        View<Grade> view = new View<Grade>(20000, "获取数据成功");
        
        Grade grade = null;
        if (id != null) {
            grade = gradeService.selectGrade(id);
        } else {
            grade = new Grade();
        }

        view.setData(grade);
        return view;
    }
    
    /**
     * 获取等级列表
     * @param request
     * @param response
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/list/all")
    public View<List<Grade>> list(HttpServletRequest request, HttpServletResponse response) {
        View<List<Grade>> view = new View<List<Grade>>(20000, "获取列表成功");

        List<Grade> gradeList = gradeService.getGradeList();
        
        view.setData(gradeList);
        
        return view;
    }
}